﻿using System;
using System.Data;
using System.Collections;
public partial class _Default : System.Web.UI.Page 
{
    Data data = new Data();
    protected void Page_Load(object sender, EventArgs e)
    {
        FillMenuTrai();
        if (IsPostBack == false)
        {
            FillVideos();
        }
        FillBanTinPhapLuat();
        FillYKienKhachHang();
        FillDanhNgon();
        if (Request.RawUrl.IndexOf("MucPhapLuatID") != -1 && IsPostBack == false)
        {
            FillCauHoiPhapLuat(Request.QueryString["MucPhapLuatID"]);
        }
        else 
        {
            FillCauHoiPhapLuat("");
        }
        FillYahoo();
        FillHTML();
    }

    private void FillYahoo()
    {
        string result ="";
        DataTable table = data.GetTable_By_Name("Yahoo");   
        int count = table.Rows.Count;
        if(count > 5)
        {
            for (int i = 0; i < 5; i++)
			{
                result += " <LI style='PADDING-RIGHT: 0px; PADDING-LEFT: 0px; BACKGROUND: none transparent scroll repeat 0% 0%; LEFT: -10px; PADDING-BOTTOM: 0px; BORDER-TOP-STYLE: none; PADDING-TOP: 0px; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; TOP: 55px; BORDER-BOTTOM-STYLE: none'>" +
                              "<A style='PADDING-RIGHT: 0px; PADDING-LEFT: 0px; BACKGROUND: none transparent scroll repeat 0% 0%; PADDING-BOTTOM: 0px; BORDER-TOP-STYLE: none; PADDING-TOP: 0px; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-BOTTOM-STYLE: none' href='ymsgr:sendim?"+table.Rows[i]["YahooAddress"].ToString()+"' target=_self>" +
                              "<SPAN style='COLOR: #fff; MARGIN-RIGHT: 0px'>" + table.Rows[i]["YahooName"].ToString() + "</SPAN>" +
                              "<IMG style='DISPLAY: inline; MARGIN-LEFT: 0px; WIDTH: 79px' alt=popupmenu  src='File/theme_images/yahoo_icon.png'></A>"+
                              "</LI>";
			}
        }
        else
        {
            for (int i = 0; i < count; i++)
            {
                result += " <LI style='PADDING-RIGHT: 0px; PADDING-LEFT: 0px; BACKGROUND: none transparent scroll repeat 0% 0%; LEFT: -10px; PADDING-BOTTOM: 0px; BORDER-TOP-STYLE: none; PADDING-TOP: 0px; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; TOP: 55px; BORDER-BOTTOM-STYLE: none'>" +
                                "<A style='PADDING-RIGHT: 0px; PADDING-LEFT: 0px; BACKGROUND: none transparent scroll repeat 0% 0%; PADDING-BOTTOM: 0px; BORDER-TOP-STYLE: none; PADDING-TOP: 0px; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-BOTTOM-STYLE: none' href='ymsgr:sendim?" + table.Rows[i]["YahooAddress"].ToString() + "' target=_self>" +
                                "<SPAN style='COLOR: #fff; MARGIN-RIGHT: 0px'>" + table.Rows[i]["YahooName"].ToString() + "</SPAN>" +
                                "<IMG style='DISPLAY: inline; MARGIN-LEFT: 0px; WIDTH: 79px' alt=popupmenu  src='File/theme_images/yahoo_icon.png'></A>" +
                                "</LI>";
            }
        }
        ltlYahoo.Text = result;
    }

    private void FillMenuTrai()
    {
        string sourceMenuTrai = "<script type='text/javascript'>" + Environment.NewLine +
                                "function JSCook_menu_502e282f1438a_addEvent( obj, type, fn )"+ Environment.NewLine +
                                "{" + Environment.NewLine +
                                   "if (obj.addEventListener) {" + Environment.NewLine +
                                      "obj.addEventListener( type, fn, false );" + Environment.NewLine +
                                   "} else if (obj.attachEvent) {" + Environment.NewLine +
                                      "obj[\"e\"+type+fn] = fn;" + Environment.NewLine +
                                      "obj[type+fn] = function() { obj[\"e\"+type+fn]( window.event ); }" + Environment.NewLine +
                                      "obj.attachEvent( \"on\"+type, obj[type+fn] );" + Environment.NewLine +
                                   "}" + Environment.NewLine +
                                "}" + Environment.NewLine +
                                "function JSCook_menu_502e282f1438a_removeEvent( obj, type, fn )" + Environment.NewLine +
                                "{" + Environment.NewLine +
                                   "if (obj.removeEventListener) {" + Environment.NewLine +
                                      "obj.removeEventListener( type, fn, false );" + Environment.NewLine +
                                   "} else if (obj.detachEvent) {" + Environment.NewLine +
                                      "obj.detachEvent( \"on\"+type, obj[type+fn] );" + Environment.NewLine +
                                      "obj[type+fn] = null;" + Environment.NewLine +
                                      "obj[\"e\"+type+fn] = null;" + Environment.NewLine +
                                   "}" + Environment.NewLine +
                                "}" + Environment.NewLine +
                                "var JSCook_menu_502e282f1438a = " + Environment.NewLine +
                                "["  + Environment.NewLine ;

        ArrayList MenuParent = MenuTrai.MenuParent();
        bool checkParent=false;
        for (int i = 0; i < MenuParent.Count; i++)
        {
            if (data.CheckMenuParent(MenuParent[i].ToString().Split(';')[1])  == false )
            {
                sourceMenuTrai += "[ '<img src=\"File/theme_images/iconmenumore.gif\" />','" + MenuParent[i].ToString().Split(';')[2] + "','Tu-Van-Phap-Luat/Default.aspx?MucPhapLuatID=" + MenuParent[i].ToString().Split(';')[0] + "',null,'" + MenuParent[i].ToString().Split(';')[2] + "'" +
                                    Environment.NewLine + "]," + Environment.NewLine;
            }
            else
            {
                sourceMenuTrai += "[ '<img src=\"File/theme_images/iconmenumore.gif\" />','" + MenuParent[i].ToString().Split(';')[2] + "','Tu-Van-Phap-Luat/Default.aspx?MucPhapLuatID=" + MenuParent[i].ToString().Split(';')[0] + "',null,'" + MenuParent[i].ToString().Split(';')[2] + "'," +
                                    Environment.NewLine; 
            }
            ArrayList menuChild = MenuTrai.MenuChild( MenuParent[i].ToString().Split(';')[1]);
            for (int j = 0; j < menuChild.Count; j++)
            {
                checkParent=true;
                sourceMenuTrai += "[ '<img src=\"File/theme_images/iconmenumore.gif\" />','" + menuChild[j].ToString().Split(';')[1] + "','Tu-Van-Phap-Luat/Index.aspx?MucPhapLuatID=" + MenuParent[i].ToString().Split(';')[0] + "&MucPhapLuatName=" + MenuParent[i].ToString().Split(';')[1] + "&MucPhapLuatCon=" + menuChild[j].ToString().Split(';')[2] + "',null,'" + menuChild[j].ToString().Split(';')[1] + "'" +
                                        Environment.NewLine + "]," + Environment.NewLine;
            }
            if(checkParent==true)
            {
                sourceMenuTrai = sourceMenuTrai.Substring(0, sourceMenuTrai.Length - 3) + "],";
                checkParent = false;
            }
        }
        sourceMenuTrai = sourceMenuTrai.Substring(0, sourceMenuTrai.Length - 3) + "]]];";
        sourceMenuTrai += "cmDrawNow =function() { cmDraw ('div_JSCook_menu_502e282f1438a', JSCook_menu_502e282f1438a, 'vbr', cmThemeOffice, 'ThemeOffice'); };" +
	"JSCook_menu_502e282f1438a_addEvent( window, \"load\", cmDrawNow, false );"+
"</script>";
        LtlMenuTrai.Text = sourceMenuTrai;
    }

    private void FillVideos()
    {
        DataTable table = data.GetTable_By_Where("Videos", "order by VideoID desc");
        string[] VideoID = new string[table.Rows.Count];
        string[] VideoTieuDe = new string[table.Rows.Count];
        string[] VideoLink = new string[table.Rows.Count];
        for (int i = 0; i < table.Rows.Count; i++)
        {
            VideoID[i] = table.Rows[i]["VideoID"].ToString();
            VideoTieuDe[i] = table.Rows[i]["VideoTieuDe"].ToString();
            VideoLink[i] = table.Rows[i]["VideoLink"].ToString();
            ltlDanhSachVideo.Text += "<a href='Default.aspx?VideoLink=" + VideoLink[i] + "' style='font-size:13px;color:black;float:left;padding-bottom:5px;' ><img src='File/theme_images/bullist.gif' style='float:left;padding-right:5px;padding-top:7px' /> " + VideoTieuDe[i] + "</a><br /><br />";
        }
        if (Request.QueryString["VideoLink"] == null)
        {
            ltlYouTuBe.Text = "<iframe width='300' height='200' src='" + VideoLink[3] + "' frameborder='2' allowfullscreen></iframe>";
        }
        else
        {
            ltlYouTuBe.Text = "<iframe width='300' height='200' src='" + Request.QueryString["VideoLink"] + "' frameborder='2' allowfullscreen></iframe>";
        }
    }

    private void FillCauHoiPhapLuat(string _MucPhapLuatID)
    {
        DataTable tableCauHoiPhapLuat = new DataTable();

        ltlHoiDapTieuDe.Text = "<center><a class='hcn-title-category' href='Default.aspx?MucPhapLuatID=1'>Internet    |    <a>" +
                                     "<a class='hcn-title-category' href='Default.aspx?MucPhapLuatID=15'>Hoạt động báo chí - xuất bản </a>    |    " +
                                     "<a class='hcn-title-category' href='Default.aspx?MucPhapLuatID=16'>Thông tin truyền thông </a>    |    " +
                                     "<a class='hcn-title-category' href='Default.aspx?MucPhapLuatID=17'>Doanh nghiệp </a>    |    " +
                                     "<a class='hcn-title-category' href='Default.aspx?MucPhapLuatID=18'>Hợp Đồng </a>    |    " +
                                     "<a class='hcn-title-category' href='Default.aspx?MucPhapLuatID=19'>Lao động </a>    |    " +
                                     "<a class='hcn-title-category' href='Default.aspx?MucPhapLuatID=20'>Bản quyền </a>    |    " +
                                     "<a class='hcn-title-category' href='Default.aspx?MucPhapLuatID=21'>Sở hữu trí tuệ </a>    |    " +
                                     "<a class='hcn-title-category' href='Default.aspx?MucPhapLuatID=22'>Cấp phép </a></center>";
        ltlHoiDapTieuDe2.Text =
                                 "<center><a class='hcn-title-category' href='Default.aspx?MucPhapLuatID=23'>Thuế- Kế toán</a>  |  " +
                                 "<a class='hcn-title-category' href='Default.aspx?MucPhapLuatID=24'>Tài chính – Ngân hàng</a>  | " +
                                 "<a class='hcn-title-category' href='Default.aspx?MucPhapLuatID=25'>Đầu tư nước ngoài</a> | " +
                                 "<a class='hcn-title-category' href='Default.aspx?MucPhapLuatID=26'>Xây dựng – Dự án</a> | " +
                                 "<a class='hcn-title-category' href='Default.aspx?MucPhapLuatID=27'>Đất đai</a> | " +
                                 "<a class='hcn-title-category' href='Default.aspx?MucPhapLuatID=28'>Hôn nhân gia đình</a> | " +
                                 "<a class='hcn-title-category' href='Default.aspx?MucPhapLuatID=29'>Dân sự</a> | " +
                                 "<a class='hcn-title-category' href='Default.aspx?MucPhapLuatID=30'>Hành chính</a> | " +
                                 "<a class='hcn-title-category' href='Default.aspx?MucPhapLuatID=31'>Hình sự</a></center>";
        if (_MucPhapLuatID == "")
        {
            tableCauHoiPhapLuat = data.GetTable_By_Where("HoiDap", "where MucPhapLuatID=1 order by HoiDapID desc");
        }
        else
        {
            tableCauHoiPhapLuat = data.GetTable_By_Where("HoiDap", "where MucPhapLuatID=" + _MucPhapLuatID + " order by HoiDapID desc");
        }
        ListviewCauHoiPhapLuat.DataSource = tableCauHoiPhapLuat;
        ListviewCauHoiPhapLuat.DataBind();
    }

    private void FillDanhNgon()
    {
        DataTable tableDanhNgon = data.GetTable_By_Where("ThongTinCoDinh", "where TTCoDinhName='DanhNgon'");
        string DanhNgonName = tableDanhNgon.Rows[0]["TTCoDinhNoiDung"].ToString();
        string DanhNgonImage = tableDanhNgon.Rows[0]["TTCoDinhImage"].ToString();
        ltlDanhNgon_Anh.Text = "<img src='Images/DanhNgon/" + DanhNgonImage + "' style='border:1px;border-style:solid;border-color:Silver;padding:3px;width: 100px;height:120px; margin-left: 5px;margin-right: 5px;margin-top: 5px;float: left;'></img>";
        ltlDanhNgon_ChuChay.Text = "<div style='background-color:#D4D4D4;text-align:left;'><i><p style='font-family:Carolina'>" + DanhNgonName + "<p></i></div>";
    }

    private void FillYKienKhachHang()
    {
        DataTable tableYKienKH = data.GetTable_By_Name_And_Top("YKienKhachHang", 3, "YKienKhachHangID");
        string[] YKienKhachHangID = new string[3];
        string[] YKienKhachHangHoTen = new string[3];
        string[] YKienKhachHangNgayDang = new string[3];
        string[] YKienKhachHangTieuDe = new string[3];
        string[] YKienKhachHangNoiDungTomTat = new string[3];
        for (int i = 0; i < tableYKienKH.Rows.Count; i++)
        {
            YKienKhachHangID[i] = tableYKienKH.Rows[i]["YKienKhachHangID"].ToString();
            YKienKhachHangHoTen[i] = tableYKienKH.Rows[i]["YKienKhachHangHoTen"].ToString();
            YKienKhachHangNgayDang[i] = tableYKienKH.Rows[i]["YKienKhachHangNgayDang"].ToString();
            YKienKhachHangTieuDe[i] = tableYKienKH.Rows[i]["YKienKhachHangTieuDe"].ToString();
            YKienKhachHangNoiDungTomTat[i] = tableYKienKH.Rows[i]["YKienKhachHangNoiDungTomTat"].ToString();
        }
        if (YKienKhachHangTieuDe[0] != null) if (YKienKhachHangTieuDe[0].Length > 70) { YKienKhachHangTieuDe[0] = YKienKhachHangTieuDe[0].Substring(0, 70) + " ..."; }
        if (YKienKhachHangTieuDe[1] != null) if (YKienKhachHangTieuDe[1].Length > 70) { YKienKhachHangTieuDe[1] = YKienKhachHangTieuDe[1].Substring(0, 70) + " ..."; }
        if (YKienKhachHangTieuDe[2] != null) if (YKienKhachHangTieuDe[2].Length > 70) { YKienKhachHangTieuDe[2] = YKienKhachHangTieuDe[2].Substring(0, 70) + " ..."; }
        ltlYKienKhachhang1.Text = "<p style='color:Black; font-size:15px;padding-left:10px;font-weight:bold;color:brown'> " + YKienKhachHangHoTen[0] + "</p><p  style='color:Black; font-size:13px;padding-left:10px;font-style:italic'>    - " + YKienKhachHangTieuDe[0] + "<a href='Y-Kien-Khach-Hang/Default.aspx?id=" + YKienKhachHangID[0] + "' style='color:brown'> Xem Thêm</a></p>";
        ltlYKienKhachhang2.Text = "<p style='color:Black; font-size:15px;padding-left:10px;font-weight:bold;color:brown'> " + YKienKhachHangHoTen[1] + "</p><p  style='color:Black; font-size:13px;padding-left:10px;font-style:italic'>    - " + YKienKhachHangTieuDe[1] + "<a href='Y-Kien-Khach-Hang/Default.aspx?id=" + YKienKhachHangID[1] + "' style='color:brown'> Xem Thêm</a></p>";
        ltlYKienKhachhang3.Text = "<p style='color:Black; font-size:15px;padding-left:10px;font-weight:bold;color:brown'> " + YKienKhachHangHoTen[2] + "</p><p  style='color:Black; font-size:13px;padding-left:10px;font-style:italic'>    - " + YKienKhachHangTieuDe[2] + "<a href='Y-Kien-Khach-Hang/Default.aspx?id=" + YKienKhachHangID[2] + "' style='color:brown'> Xem Thêm</a></p>";
    }

    private void FillBanTinPhapLuat()
    {
        DataTable tableBanTinPhapLuat = data.GetTable_By_Name_And_Top("BanTinPhapLuat", 5, "BanTinPhapLuatID");
        string[] BanTinPhapLuatID = new string[5];
        string[] BanTinPhapLuatNgayDang = new string[5];
        string[] BanTinPhapLuatNoiDung = new string[5];
        string[] BanTinPhapLuatTieuDe = new string[5];
        string[] BanTinPhapLuatNoiDungTomTat = new string[5];
        string[] BanTinPhapLuatBinhLuan = new string[5];
        string[] BanTinPhapLuatImages = new string[5];
        for (int i = 0; i < tableBanTinPhapLuat.Rows.Count; i++)
        {
            BanTinPhapLuatID[i] = tableBanTinPhapLuat.Rows[i]["BanTinPhapLuatID"].ToString();
            BanTinPhapLuatNgayDang[i] = tableBanTinPhapLuat.Rows[i]["BanTinPhapLuatNgayDang"].ToString();
            BanTinPhapLuatNoiDung[i] = tableBanTinPhapLuat.Rows[i]["BanTinPhapLuatNoiDung"].ToString();
            BanTinPhapLuatTieuDe[i] = tableBanTinPhapLuat.Rows[i]["BanTinPhapLuatTieuDe"].ToString();
            BanTinPhapLuatNoiDungTomTat[i] = tableBanTinPhapLuat.Rows[i]["BanTinPhapLuatNoiDungTomTat"].ToString();
            BanTinPhapLuatBinhLuan[i] = tableBanTinPhapLuat.Rows[i]["BanTinPhapLuatBinhLuan"].ToString();
            BanTinPhapLuatImages[i] = tableBanTinPhapLuat.Rows[i]["BanTinPhapLuatImages"].ToString();
        }
        ltlBanTinPhapLuat0.Text = "<a href='Ban-Tin-Phap-Luat/Default.aspx?id=" + BanTinPhapLuatID[0] + "' style='font-weight:bold;color:Black;font-size:13px;padding-left:10px'>" + BanTinPhapLuatTieuDe[0] + "</a>";
        if(BanTinPhapLuatImages[0].IndexOf(';') != -1)
        {
            //ltlBanTinPhapLuatImage0.Text = "<a href='Ban-Tin-Phap-Luat/Default.aspx?id=" + BanTinPhapLuatID[0] + "'> <img src='" + "Images/AnhBanTinPhapLuat/" + BanTinPhapLuatImages[0].Split(';')[0] + "' width='150' height='100' hspace='5' vspace='5' align='left' BorderColor=Silver hspace=5 vspace=5  BorderWidth=1 align=left style='padding-right:10px;' ></a>";
            ltlBanTinPhapLuatImage0.Text = "<a href='Ban-Tin-Phap-Luat/Default.aspx?id=" + BanTinPhapLuatID[0] + "' > <img src='" + "Images/AnhBanTinPhapLuat/" + BanTinPhapLuatImages[0].Split(';')[0] + "' style='border:1px;border-style:solid;border-color:Silver;padding:3px;width: 150px;height=150px;margin-left: 5px;margin-right: 5px;margin-top: 5px;margin-bottom: 5px;float: left;vertical-align: top;' ></a>";
        }
        else
        {
            ltlBanTinPhapLuatImage0.Text = "<a href='Ban-Tin-Phap-Luat/Default.aspx?id=" + BanTinPhapLuatID[0] + "' > <img src='" + "Images/AnhBanTinPhapLuat/" + BanTinPhapLuatImages[0] + "' style='border:1px;border-style:solid;border-color:Silver;padding:3px;width: 150px;height=150px;margin-left: 5px;margin-right: 5px;margin-top: 5px;margin-bottom: 5px;float: left;vertical-align: top;padding-right:20px;' ></a>";
        }
        ltlBanTinPhapLuatTomTat0.Text = "<p style='color:Black;font-size:13px;'>"+BanTinPhapLuatNoiDungTomTat[0]+"</p>";
        ltlBanTinPhapLuat1.Text = " <a href='Ban-Tin-Phap-Luat/Default.aspx?id=" + BanTinPhapLuatID[1] + "' style='color:Black; font-size:13px;padding-left:10px;padding-top:20px;'><img src='File/theme_images/bullist.gif' style='float:left;padding-top:7px' />" + BanTinPhapLuatTieuDe[1] + "</a>";
        ltlBanTinPhapLuat2.Text = " <a href='Ban-Tin-Phap-Luat/Default.aspx?id=" + BanTinPhapLuatID[2] + "' style='color:Black;font-size:13px;padding-left:10px;'><img src='File/theme_images/bullist.gif' style='float:left;padding-top:7px' />" + BanTinPhapLuatTieuDe[2] + "</a>";
        ltlBanTinPhapLuat3.Text = " <a href='Ban-Tin-Phap-Luat/Default.aspx?id=" + BanTinPhapLuatID[3] + "' style='color:Black;font-size:13px;padding-left:10px;'><img src='File/theme_images/bullist.gif' style='float:left;padding-top:7px' />" + BanTinPhapLuatTieuDe[3] + "</a>";
        ltlBanTinPhapLuat4.Text = " <a href='Ban-Tin-Phap-Luat/Default.aspx?id=" + BanTinPhapLuatID[4] + "' style='color:Black;font-size:13px;padding-left:10px;'><img src='File/theme_images/bullist.gif' style='float:left;padding-top:7px' />" + BanTinPhapLuatTieuDe[4] + "</a>";
      
    }

    private void FillHTML()
    {
        ltl_AnhChay.Text = SourceAnhChay.SlideAnh();
        ltl5anh.Text = SourceAnhChay.Slide5anh();
    }

    protected void DataPagerProducts_PreRender(object sender, EventArgs e)
    {
        this.ListviewCauHoiPhapLuat.DataBind();
    }

    
}
